package com.mallcai.bigdata.ladon.dpl.mapper.peekdata;

import com.mallcai.bigdata.ladon.dpl.entity.peekdata.ModelMeta;
import com.mallcai.bigdata.ladon.dpl.mapper.peekdata.provider.ModelMetaSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

import static com.mallcai.bigdata.ladon.dpl.mapper.peekdata.provider.ModelMetaSqlProvider.TB_MODEL_META;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
@Repository
public interface ModelMetaMapper {

    @InsertProvider(type = ModelMetaSqlProvider.class, method = "insert")
    int insert(ModelMeta modelMeta);

    @UpdateProvider(type = ModelMetaSqlProvider.class, method = "update")
    int update(ModelMeta modelMeta);

    @SelectProvider(type = ModelMetaSqlProvider.class, method = "getByNames")
    List<ModelMeta> getByNames(@Param("modelId") Long modelId, @Param("names") List<String> names);

    @Delete({
            "DELETE FROM " + TB_MODEL_META + " WHERE id = #{id}"
    })
    int delete(ModelMeta modelMeta);

    @Select({
            "SELECT * FROM " + TB_MODEL_META + " WHERE archive = 0 and model_id = #{modelId}"
    })
    List<ModelMeta> getByModelId(@Param("modelId") Long modelId);

    @Select({
            "SELECT * FROM " + TB_MODEL_META + " WHERE archive = 0 and id = #{id}"
    })
    ModelMeta getById(@Param("id") Long id);

    @Delete({
            "DELETE FROM " + TB_MODEL_META + " WHERE model_id = #{modelId}"
    })
    int delByModelId(@Param("modelId") Long modelId);

    @Select({
        "SELECT DISTINCT group_name FROM " + TB_MODEL_META + " WHERE display = 1 AND  model_id = #{modelId}"
    })
    List<String> getColumnsGroupByModelId(@Param("modelId") Long modelId);


    @SelectProvider(type = ModelMetaSqlProvider.class, method = "getByIds")
    List<ModelMeta> getByIds( @Param("ids") Collection<Long> ids);

}
